
/*******************************************************************************
 * The code below this comment is integral part of the project "Jelliphy".
 * 
 * "Jelliphy" is a project created by: 
 * Dispage - Patrizio Gelosi
 * Via A. De Gasperi 91 
 * P. Potenza Picena (MC) - Italy
 * 
 * (Hereby referred to as "DISPAGE")
 * 
 * Copyright (c) 2011 DISPAGE.
 * 
 * @Released on: 02-06-2011
 * @Version: 1.0.00
 * @Build: 1109
 * @Site: http://www.dispage.com
 * @Contacts: http://www.dispage.com/contacts
 * 
 * The contents of this file are released under the GNU General Public License
 * version 3 as published by the Free Software Foundation that can be found at
 * the address "http://opensource.org/licenses/gpl-3.0.html". If the license
 * cannot be found, write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * You may not use the present file except in compliance with the License.
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * Dispage" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by Dispage".
 * 
 ******************************************************************************/

var MGL = new function () {

	var cancel = function () {

			JlQ('#mg-login-request').val("0");
			JlQ('#mg-login-remove').val("1");
			JlQ('#mg-login').trigger('submit');
		},

		keyDown = function (ev) {

			var keyCode = ev.keyCode || ev.which;

			if (keyCode == 13) submit();
		},

		submit = function () {

			if (!JlQ('#mg-username').val() || !JlQ('#mg-password').val()) {
				MGDial.warning(MGLang.warnings.uid_pwd_empty);
				return -1;
			}
			JlQ('#mg-login').trigger('submit');
		};


	this.loginError = false;


	this.init = function () {

		JlQ('.mg-panel-login').draggable({ 
				cancel: '.mg-subpanel, .mg-subpanel-element',
				cursor: 'move'
			})
			.resizable({minHeight: 124, minWidth: 260, alsoResize: '.mg-panel-login .mg-subpanel-element'})
			.keydown(keyDown);

		MGBP.initBasicPanels();

		MGBP.initBasicButtons();

		JlQ('#mg-login-cancel').click(cancel);
		JlQ('#mg-login-submit').click(submit);

		JlQ('#mg-login').attr('action', MGUtils.removeURIParArray([MGAccessKey]));

		if (MGL.loginError)	{
			MGDial.warning(MGLang.warnings.uid_pwd_wrong);
		}
	}
}

JlQ(document).ready(MGL.init);
